<%@page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@include file="/includes/taglibs.jsp"%>
<%@page import="com.feib.stms.action.GroupActionBean"%>
<%@page import="com.feib.stms.util.StmsUtil"%>
<%@page import="com.feib.stms.model.LabelValue"%>

<%
// 欄位排序處理
GroupActionBean actionBean = (GroupActionBean) request.getAttribute("actionBean");
actionBean.setNavigator();
pageContext.setAttribute("actionBeanClassName", actionBean.getClass().getName());
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>券商查詢</title>
            
    <script type="text/javascript">
    <!-- 
    
    window.name = 'queryGroup';
    
    
    $(document).ready(function() {

        //var dialogArgs = window.dialogArguments;
        //var parentWindowObj = dialogArgs.parentWindowObj;
        
<%
if ("doQuerySecurities".equalsIgnoreCase(actionBean.getContext().getEventName())){
%>

var dialogArgs = window.dialogArguments;
var parentWindowObj = dialogArgs.parentWindowObj;
parentWindowObj.document.getElementById(dialogArgs.groupNoId).value = document.getElementById('hidden.editGroup.groupNo').value;
parentWindowObj.document.getElementById(dialogArgs.groupNameId).innerHTML = document.getElementById('hidden.editGroup.groupName').value;
parentWindowObj.document.getElementById(dialogArgs.groupPkId).value = document.getElementById('hidden.editGroup.groupPk').value;

if(null!=parentWindowObj.document.getElementById(dialogArgs.checkboxDiv)){
	parentWindowObj.document.getElementById(dialogArgs.checkboxDiv).innerHTML = document.getElementById('returnSecuritesCheckbox').innerHTML;
}

window.close();
	
<%
}
%>
    	
<c:if test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">


		$("[id^='returnGroupPk-']").click(function() {
			var pk = this.id.substring(14);
			$('#hidden\\.qryGroup\\.groupPk').val(pk);
			
			waitingDialog({});
			$("#hidden\\.doQuerySecuritiesBtn").trigger('click');			
			return false; <%// 此行一定要有，不然ie6不會執行submit%>
			

		});

		$("[id^='a-sortHeader-']").live("click", function() {
			var sortField = this.id.substring(13);
			$('#hidden\\.queryResult\\.sortCriterion').val(sortField);
			
			var clazz = $(this).attr('class');
			if (null == clazz || 0 == clazz.length)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else if ('sortAsc' == clazz)
				$('#hidden\\.queryResult\\.sortDirection').val('1');
			else
				$('#hidden\\.queryResult\\.sortDirection').val('2');
				
			$('#hidden\\.queryResult\\.pageNumber').val('1');
			
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');			
			return false; <%// 此行一定要有，不然ie6不會執行submit%>
			
		});
		
		$("[id^='firstPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('1');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='prePageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${prePageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='nextPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${nextPageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='lastPageBtn']").click(function() {
			$('#hidden\\.queryResult\\.pageNumber').val('<c:out value="${lastPageNumber}"/>');
			waitingDialog({});
			$("#hidden\\.doQueryBtn").trigger('click');
		});
		
		$("[id^='currentPageText']").change(function() {
			var value = this.value;
			if (value != ''){
				value = value.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
				var intRegex = /^\d+$/;
				if(!intRegex.test(value)) {
					showErrorMessageDialog('頁數必須是整數');
					return ;
				}
				
				value = parseInt(value, 10);
				
				if (value < 1){
					showErrorMessageDialog('頁數必須是大於1');
					return ;
				}
				else if (value > <c:out value='${lastPageNumber}'/>){
					showErrorMessageDialog('頁數必須是小於總頁數 (<c:out value="${lastPageNumber}"/>)');
					return ;
				}
				else if (value != <c:out value='${currentPageNumber}'/>){
					doQueryAction();
					$('#hidden\\.queryResult\\.pageNumber').val(value);
					waitingDialog({});
					$("#hidden\\.doQueryBtn").trigger('click');
				}
				
			}
			else{
				showErrorMessageDialog('頁數不可為空白)');
				return ;
			}
		});
</c:if>
    	
    	<c:if test="${not empty actionBean.message}">
    	showMessageDialog('<c:out value="${actionBean.message }" escapeXml="false"/>');
    	</c:if>
	});
    //-->
    </script>
</head>
<body>

	<div id="smallQueryForm"></div>

<stripes:form id="queryGroupFrom" beanclass="com.feib.stms.action.GroupActionBean" method="post" onsubmit="javascript: waitingDialog({});" target="queryGroup">	
	<div id="queryForm">
		<table>
			<tr>
				<td colspan="4" class="queryHeader">請輸入查詢條件</td>
			</tr>
			<tr>
				<th>券商代號</th>
				<td colspan="3"><stripes:text id="qryGroup.groupNo" name="qryGroup.groupNo" size="12" maxlength="12"></stripes:text></td>
			</tr>
			<tr>
				<th>名稱</th>
				<td colspan="3"><stripes:text id="qryGroup.groupName" name="qryGroup.groupName" size="20" maxlength="20"></stripes:text></td>
			</tr>
			<tr>
				<td colspan="4" class="queryFunction">
					<stripes:submit id="doQueryBtn" name="doQuery" value="查詢" class="formBtn"/>
					<input type="button" value="離開" id="doCloseGroupsBtn1" onclick="javascript:window.close();"/>
				</td>
			</tr>
		</table>
	</div>
</stripes:form>
	

	<div id="listForm">
<c:if test="${null != actionBean.queryResult && not empty actionBean.queryResult.paginatedList}">

			<div id="paginationBar" style=" margin: 0 auto;">
			<input type="button" id="firstPageBtn" class="formBtn" value="第一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			<input type="button" id="prePageBtn" class="formBtn" value="上一頁" <c:out value='${prePageNumber<=0 ? "disabled": "" }'/> />
			第 <input type="text" id="currentPageText" class="formBtn" value="${currentPageNumber }" size="3" maxlength="4" /> / ${lastPageNumber} 頁
			<input type="button" id="nextPageBtn" class="formBtn" value="下一頁" <c:out value='${lastPageNumber<nextPageNumber ? "disabled": "" }'/> />
			<input type="button" id="lastPageBtn" class="formBtn" value="最末頁" <c:out value='${lastPageNumber<=currentPageNumber ? "disabled": "" }'/> />
			</div>
                
                <table id="queryResultTable">
				<thead>
					<tr>
						<th>序號</th>
						<th><a id='a-sortHeader-groupNo' href='javascript:void(0);' class="<c:out value='${groupNoSortedClass }'/>"><c:out value='${groupNoSortedSpan }' escapeXml="false"/>券商代號 </a> </th>						
						<th><a id='a-sortHeader-groupName' href='javascript:void(0);' class="<c:out value='${groupNameSortedClass }'/>"> <c:out value='${groupNameSortedSpan }' escapeXml="false"/>券商戶名</a></th>
                    </tr>
				</thead>
				<tbody>
                    <c:forEach items="${actionBean.queryResult.paginatedList}" var="viewObj" varStatus="rowstat">
                    <tr id="returnGroupPk-<c:out value="${viewObj.groupPk }" />" >
                        <td align="right"><c:out value='${ rowstat.index + 1}'/></td>
                        <td><c:out value="${viewObj.groupNo }" /></td>
                        <td><c:out value="${viewObj.groupName }" /></td>
                    </tr>
                    </c:forEach>
				</tbody>
				<tfoot>
					<tr>
						<td colspan="16" class="listFunction">
							<input type="button" value="離開" id="doCloseGroupsBtn2" onclick="javascript:window.close();"/>
						</td>
					</tr>
				</tfoot>
                </table>
</c:if>
	</div>

<div style="display: none;">
<stripes:form id="hidden.queryGroupFrom" beanclass="com.feib.stms.action.GroupActionBean" method="post" onsubmit="javascript: waitingDialog({});" target="queryGroup">
	
	<stripes:hidden id="hidden.queryResult.pageNumber" name="queryResult.pageNumber" />
	<stripes:hidden id="hidden.queryResult.sortCriterion" name="queryResult.sortCriterion" />
	<stripes:hidden id="hidden.queryResult.sortDirection" name="queryResult.sortDirection" />
	<stripes:hidden id="hidden.qryGroup.groupNo" name="qryGroup.groupNo" />
	<stripes:hidden id="hidden.qryGroup.groupName" name="qryGroup.groupName" />
	<stripes:hidden id="hidden.qryGroup.groupPk" name="qryGroup.groupPk" />
	<stripes:hidden id="hidden.editGroup.groupNo" name="editGroup.groupNo" />
	<stripes:hidden id="hidden.editGroup.groupName" name="editGroup.groupName" />
	<stripes:hidden id="hidden.editGroup.groupPk" name="editGroup.groupPk" />
	<stripes:submit id="hidden.doQueryBtn" name="doQuery" value="查詢" class="formBtn"/>
	<stripes:submit id="hidden.doQuerySecuritiesBtn" name="doQuerySecurities" value="查詢" class="formBtn"/>
	<stripes:errors></stripes:errors>
</stripes:form>
</div>

<div id="returnSecuritesCheckbox" style="display: none;">
	<c:forEach items="${actionBean.securities}" var="branchObj" varStatus="rowstat">
		<input value="<c:out value="${branchObj.securitiesNo}" />" type="checkbox" class="qrychk" name="qrySecuritiesNos[${rowstat.index}]" id="qrySecuritiesNos[${rowstat.index}]" /> <c:out value="${branchObj.securitiesName}" />&nbsp;
	</c:forEach>
</div>
</body>
</html>
